﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common;
using System.Data;

namespace Catering.UserTraining.SlrCompanyTrainning
{
    public partial class cpntraining_test_list : UserIsNull
    {
        public string m_UserID = "0";
        public int m_LessonID = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] != null) m_UserID = Session["UserID"].ToString();
            m_LessonID = CommRequest.GetInt("LessonID", 0);
            if (!IsPostBack)
            {
                this.LoadRep();
            }
        }


        protected void btnSearch_Click(object sender, EventArgs e)
        {
            this.LoadRep();
        }

        //绑定Rep控件
        public void LoadRep()
        {
            DataTable dt_PurchaseInfo = new Catering_Rules.StaffLessonsTests().ViewGetList(" 1=1 AND LessonID=" + m_LessonID + " ").Tables[0];//分页处理
            this.Repeater1.DataSource = dt_PurchaseInfo;
            this.Repeater1.DataBind();
        }

        //绑定Rep控件
        public void LoadRep(string strwhere)
        {
            LoadRep();
        }

        /// <summary>
        /// 新增功能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string url = "~/UserTraining/SlrCompanyTrainning/cpntraining_test_add.aspx?LessonID=" + m_LessonID;
            Response.Redirect(url);
        }

        protected void btn_ReturnIndex_Click(object sender, EventArgs e)
        {
            string url = "~/UserTraining/SlrCompanyTrainning/cpntraining_lessons_list.aspx";
            Response.Redirect(url);
        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            int TestID = int.Parse(e.CommandArgument.ToString());
            if (TestID <= 0) return;
            if (e.CommandName == "del")
            {
                if (new Catering_Rules.StaffLessonsTests().Delete(m_LessonID, TestID) && new Catering_Rules.Tests().Delete(TestID))
                {
                    this.LoadRep();
                    ScriptManager.RegisterStartupScript(this, GetType(), "Affect", "alert('删除成功！')", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "Affect", "alert('删除失败！')", true);
                }
            }
            else if (e.CommandName == "edit")
            {
                string url = "~/UserTraining/SlrCompanyTrainning/cpntraining_test_add.aspx?Flag=EDIT&LessonID=" + m_LessonID + "&TestID=" + TestID;
                Response.Redirect(url);
            }
            else if (e.CommandName == "tknr")
            {
                string url = "~/UserTraining/SlrCompanyTrainning/cpntraining_test_que_list.aspx?LessonID=" + m_LessonID + "&TestID=" + TestID;
                Response.Redirect(url);
            }
        }
    }
}